package com.cskaoyan.exception;


import com.cskaoyan.bean.CommentExample;
import com.cskaoyan.bean.basebean.BaseRespVo;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
public class ExceptionControllerAdvice {


    @ExceptionHandler(AdException.class)
    public BaseRespVo adException() {
        return BaseRespVo.fail();
    }

    @ExceptionHandler(CouponException.class)
    public BaseRespVo couponException() {
        return BaseRespVo.fail();
    }

    @ExceptionHandler(TopicException.class)
    public BaseRespVo topicException() {
        return BaseRespVo.fail();
    }

    @ExceptionHandler(GoodsToTopicException.class)
    public BaseRespVo goodsToTopicException() {
        return BaseRespVo.fail();
    }

    @ExceptionHandler(MarketException.class)
    @ResponseBody
    public BaseRespVo errorMessage(MarketException e){
        return BaseRespVo.fail(e.getMessage());
    }

    @ExceptionHandler(IllegalAccessException.class)
    @ResponseBody
    public BaseRespVo illegalAccessException(){
        return BaseRespVo.fail("非法访问！");
    }

    @ResponseBody
    @ExceptionHandler(LoginFailException.class)
    public BaseRespVo loginFailException(){
        return BaseRespVo.fail("用户名或密码错误");
    }

    @ResponseBody
    @ExceptionHandler(AuthorizationException.class)
    public BaseRespVo authorizationException(){
        return BaseRespVo.fail("权限认证失败");
    }

    @ResponseBody
    @ExceptionHandler(IncorrectCredentialsException .class)
    public BaseRespVo incorrectCredentialsException(IncorrectCredentialsException ex){
        return BaseRespVo.fail("用户名或密码错误");
    }

    @ResponseBody
    @ExceptionHandler(AddressException.class)
    public BaseRespVo addressException() {
        return BaseRespVo.fail("地址信息错误");
    }

    @ResponseBody
    @ExceptionHandler(CommentException.class)
    public BaseRespVo commentException() {
        return BaseRespVo.fail("评论非法");
    }
}
